{% extends 'base.html' %}
{% load staticfiles %}
{% load platfom_tags %}


{% block base_title %}
    {{ title }}
{% endblock base_title %}


{% block base_content %}
    <!-- 右边主体 -->
    <div class="app-content">
        <div class="app-content-body fade-in-up">
            <div class="padder" style="padding-top: 10px;">

                <div class="col-md-12" style="padding-left: 0; padding-right: 0;">
                    <div class="panel panel-default" id="body-content" style="overflow-y:scroll">
                        <div class="panel-heading" >
                            <div style="display: block; border-left: 5px solid #1c2b36; padding-left: 10px; font-size: 20px; font-weight: bolder; line-height: 25px;color: #1c2b36;">
                                {{ title }}
                            </div>
                        </div>


                        <div class="panel-body" id="table_content">

                            <div class="row">

                               <div class="col-sm-12">
                                    <table class="table table-striped table-bordered">
                                        <!-- 标题行 -->
                                        <thead>
                                        <tr role="row">
                                            <th class="text-center" width="200">测试卡配额</th>
                                            <th class="text-center" width="200">周卡配额</th>
                                            <th class="text-center" width="200">月卡配额</th>
                                            <th class="text-center" width="200">终生卡配额</th>
                                        </tr>
                                        </thead>
                                        <tbody>

                                            <tr class="gradeX odd" role="row">
                                                <td class="text-center"
                                                    style="vertical-align:middle;">{{ request.user.testcard }}
                                                </td>
                                                <td class="text-center"
                                                    style="vertical-align:middle;">{{ request.user.weekcard }}
                                                </td>
                                                <td class="text-center"
                                                    style="vertical-align:middle;">{{ request.user.monthcard }}
                                                </td>
                                                <td class="text-center"
                                                    style="vertical-align:middle;">{{ request.user.foevercard }}
                                                </td>

                                            </tr>
                                        </tbody>
                                    </table>

                            </div>


                        </div>


                                    <div class="tab-pane active" id="panel-815220">

                        <div class="panel-group" id="panel-544491">
                            <div class="panel panel-default">
                                <div class="panel-heading">
                                     <a class="panel-title collapsed" data-toggle="collapse" data-parent="#panel-544491" href="#panel-element-330646">创建单个自定义注册码</a>
                                </div>
                                <div id="panel-element-330646" class="panel-collapse collapse">
                                    <div class="panel-body">
                                        <form class="m-t" role="form" action="" id="createonedata">
                                            <div class="form-group"
                                                 style="vertical-align: middle;line-height: 34px;padding-bottom: 30px;">
                                                <div class="col-md-3">
                                                    <span style="font-size: 14px;">版本：</span>
                                                </div>
                                                <div class="col-md-9" style="padding: 0;">
                                                    <select name="version" class="selectpicker form-control" >
                                                    {% for i in request.user.versionstring %}
                                                        <option value="{{i}}">{% Get_VersionString version i %}</option>
                                                    {% endfor %}
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="form-group"
                                                 style="vertical-align: middle;line-height: 34px;padding-bottom: 30px;">
                                                <div class="col-md-3">
                                                    <span style="font-size: 14px;">类型：</span>
                                                </div>
                                                <div class="col-md-9" style="padding: 0;">
                                                    <select name="type" class="selectpicker form-control" >
                                                      <option value="试用">试用</option>
                                                      <option value="周卡">周卡</option>
                                                      <option value="月卡">月卡</option>
                                                      <option value="永久">永久</option>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="form-group"
                                                 style="vertical-align: middle;line-height: 34px;padding-bottom: 30px;">
                                                <div class="col-md-3">
                                                    <span style="font-size: 14px;">注册码：</span>
                                                </div>
                                                <div class="col-md-9" style="padding: 0;">
                                                    <input name="token" class="form-control" placeholder="注册码" required="">
                                                </div>
                                            </div>
                                            <div class="form-group"
                                                 style="vertical-align: middle;line-height: 34px;padding-bottom: 30px;">
                                                <div class="col-md-3">
                                                    <span style="font-size: 14px;">备注：</span>
                                                </div>
                                                <div class="col-md-9" style="padding: 0;">
                                                    <input name="name" class="form-control" placeholder="备注" required="">
                                                </div>
                                            </div>
                                            <div class="form-group"
                                                 style="vertical-align: middle;line-height: 34px;padding-bottom: 30px;">
                                                <div class="col-md-3">
                                                    <span style="font-size: 14px;">成交金额：</span>
                                                </div>
                                                <div class="col-md-9" style="padding: 0;">
                                                    <input name="money" class="form-control" placeholder="成交金额" required="">
                                                </div>
                                            </div>
                                        </form>
                                        <br><button  id="createone" class="btn-gray" >创建固定注册码</button>
                                    </div>
                                </div>
                            </div>

                            <div class="panel panel-default">
                                <div class="panel-heading">
                                     <a class="panel-title collapsed" data-toggle="collapse" data-parent="#panel-544491" href="#panel-element-330647">批量创建随机注册码</a>
                                </div>
                                <div id="panel-element-330647" class="panel-collapse collapse">
                                    <div class="panel-body">
                                    <form class="m-t" role="form" action="" id="createmoredata">
                                            <div class="form-group"
                                                 style="vertical-align: middle;line-height: 34px;padding-bottom: 30px;">
                                                <div class="col-md-3">
                                                    <span style="font-size: 14px;">版本：</span>
                                                </div>
                                                <div class="col-md-9" style="padding: 0;">
                                                    <select name="version" class="selectpicker form-control" >
                                                    {% for i in request.user.versionstring %}
                                                        <option value="{{i}}">{% Get_VersionString version i %}</option>
                                                    {% endfor %}
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="form-group"
                                                 style="vertical-align: middle;line-height: 34px;padding-bottom: 30px;">
                                                <div class="col-md-3">
                                                    <span style="font-size: 14px;">类型：</span>
                                                </div>
                                                <div class="col-md-9" style="padding: 0;">
                                                    <select name="type" class="selectpicker form-control" >
                                                      <option value="试用">试用</option>
                                                      <option value="周卡">周卡</option>
                                                      <option value="月卡">月卡</option>
                                                      <option value="永久">永久</option>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="form-group"
                                                 style="vertical-align: middle;line-height: 34px;padding-bottom: 30px;">
                                                <div class="col-md-3">
                                                    <span style="font-size: 14px;">数量：</span>
                                                </div>
                                                <div class="col-md-9" style="padding: 0;">
                                                    <input name="count" class="form-control" placeholder="数量" required="">
                                                </div>
                                            </div>
                                            <div class="form-group"
                                                 style="vertical-align: middle;line-height: 34px;padding-bottom: 30px;">
                                                <div class="col-md-3">
                                                    <span style="font-size: 14px;">备注：</span>
                                                </div>
                                                <div class="col-md-9" style="padding: 0;">
                                                    <input name="name" class="form-control" placeholder="备注" required="">
                                                </div>
                                            </div>
                                            <div class="form-group"
                                                 style="vertical-align: middle;line-height: 34px;padding-bottom: 30px;">
                                                <div class="col-md-3">
                                                    <span style="font-size: 14px;">成交金额：</span>
                                                </div>
                                                <div class="col-md-9" style="padding: 0;">
                                                    <input name="money" class="form-control" placeholder="成交金额" required="">
                                                </div>
                                            </div>
                                        </form>
                                        <br><button  id="createmore" class="btn-gray" >创建随机注册码</button>
                                    </div>
                                </div>
                            </div>

                            <div class="panel panel-default">
                                <div class="panel-heading">
                                     <a class="panel-title collapsed" data-toggle="collapse" data-parent="#panel-544491" href="#panel-element-330648">批量创建递增注册码</a>
                                </div>
                                <div id="panel-element-330648" class="panel-collapse collapse">
                                    <div class="panel-body">

                                    <form class="m-t" role="form" action="" id="createindexdata">
                                            <div class="form-group"
                                                 style="vertical-align: middle;line-height: 34px;padding-bottom: 30px;">
                                                <div class="col-md-3">
                                                    <span style="font-size: 14px;">版本：</span>
                                                </div>
                                                <div class="col-md-9" style="padding: 0;">
                                                    <select name="version" class="selectpicker form-control" >
                                                    {% for i in request.user.versionstring %}
                                                        <option value="{{i}}">{% Get_VersionString version i %}</option>
                                                    {% endfor %}
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="form-group"
                                                 style="vertical-align: middle;line-height: 34px;padding-bottom: 30px;">
                                                <div class="col-md-3">
                                                    <span style="font-size: 14px;">类型：</span>
                                                </div>
                                                <div class="col-md-9" style="padding: 0;">
                                                    <select name="type" class="selectpicker form-control" >
                                                      <option value="试用">试用</option>
                                                      <option value="周卡">周卡</option>
                                                      <option value="月卡">月卡</option>
                                                      <option value="永久">永久</option>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="form-group"
                                                 style="vertical-align: middle;line-height: 34px;padding-bottom: 30px;">
                                                <div class="col-md-3">
                                                    <span style="font-size: 14px;">自定义字符：</span>
                                                </div>
                                                <div class="col-md-9" style="padding: 0;">
                                                    <input name="diycode" class="form-control" placeholder="自定义字符" required="">
                                                </div>
                                            </div>
                                            <div class="form-group"
                                                 style="vertical-align: middle;line-height: 34px;padding-bottom: 30px;">
                                                <div class="col-md-3">
                                                    <span style="font-size: 14px;">数量：</span>
                                                </div>
                                                <div class="col-md-9" style="padding: 0;">
                                                    <input name="count" class="form-control" placeholder="数量" required="">
                                                </div>
                                            </div>
                                            <div class="form-group"
                                                 style="vertical-align: middle;line-height: 34px;padding-bottom: 30px;">
                                                <div class="col-md-3">
                                                    <span style="font-size: 14px;">备注：</span>
                                                </div>
                                                <div class="col-md-9" style="padding: 0;">
                                                    <input name="name" class="form-control" placeholder="备注" required="">
                                                </div>
                                            </div>
                                            <div class="form-group"
                                                 style="vertical-align: middle;line-height: 34px;padding-bottom: 30px;">
                                                <div class="col-md-3">
                                                    <span style="font-size: 14px;">成交金额：</span>
                                                </div>
                                                <div class="col-md-9" style="padding: 0;">
                                                    <input name="money" class="form-control" placeholder="成交金额" required="">
                                                </div>
                                            </div>
                                        </form>
                                        <br><button  id="createindex" class="btn-gray" >创建自定义注册码</button>
                                    </div>
                                </div>
                            </div>
                        {% if request.user.role > 1 %}
                            <div class="panel panel-default">
                                <div class="panel-heading">
                                     <a class="panel-title collapsed" data-toggle="collapse" data-parent="#panel-544491" href="#panel-element-330649">配额转让</a>
                                </div>
                                <div id="panel-element-330649" class="panel-collapse collapse">
                                    <div class="panel-body">

                                    <form class="m-t" role="form" action="" id="transferdata">
                                            <div class="form-group"
                                                 style="vertical-align: middle;line-height: 34px;padding-bottom: 30px;">
                                                <div class="col-md-3">
                                                    <span style="font-size: 14px;">类型：</span>
                                                </div>
                                                <div class="col-md-9" style="padding: 0;">
                                                    <select name="type" class="selectpicker form-control" >
                                                      <option value="试用">试用</option>
                                                      <option value="周卡">周卡</option>
                                                      <option value="月卡">月卡</option>
                                                      <option value="永久">永久</option>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="form-group"
                                                 style="vertical-align: middle;line-height: 34px;padding-bottom: 30px;">
                                                <div class="col-md-3">
                                                    <span style="font-size: 14px;">目标用户账号：</span>
                                                </div>
                                                <div class="col-md-9" style="padding: 0;">
                                                    <input name="username" class="form-control" placeholder="目标用户账号" required="">
                                                </div>
                                            </div>
                                            <div class="form-group"
                                                 style="vertical-align: middle;line-height: 34px;padding-bottom: 30px;">
                                                <div class="col-md-3">
                                                    <span style="font-size: 14px;">数量：</span>
                                                </div>
                                                <div class="col-md-9" style="padding: 0;">
                                                    <input name="count" class="form-control" placeholder="数量" required="">
                                                </div>
                                            </div>
                                            <div class="form-group"
                                                 style="vertical-align: middle;line-height: 34px;padding-bottom: 30px;">
                                                <div class="col-md-3">
                                                    <span style="font-size: 14px;">备注：</span>
                                                </div>
                                                <div class="col-md-9" style="padding: 0;">
                                                    <input name="name" class="form-control" placeholder="备注" required="">
                                                </div>
                                            </div>
                                            <div class="form-group"
                                                 style="vertical-align: middle;line-height: 34px;padding-bottom: 30px;">
                                                <div class="col-md-3">
                                                    <span style="font-size: 14px;">成交金额：</span>
                                                </div>
                                                <div class="col-md-9" style="padding: 0;">
                                                    <input name="money" class="form-control" placeholder="成交金额" required="">
                                                </div>
                                            </div>
                                        </form>
                                        <br><button  id="transfer" class="btn-gray" >配额转让</button>
                                    </div>
                                </div>
                            </div>
                        {% endif %}
			        </div>

					</div>

                    </div>
                </div>
            </div>
        </div>
    </div>
    </div>
{% endblock base_content %}

{% block base_footer_html %}

<div class="modal fade" id="modal-container-873864" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
				<div class="modal-dialog">
					<div class="modal-content">
						<div class="modal-header">
                       <table class="table table-hover" border="1"cellpadding="10" cellspacing="0" id="tokendisplay"></table>
						<div class="modal-footer">
							 <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
						</div>
					</div>
				</div>
			</div>
		</div>

        <script>

                $('#createone').on('click', function () {
                    $.ajax({
                        cache: false,
                        type: "POST",
                        url: "{% url 'topnews:tokencreateone' %}",
                        data: $('#createonedata').serialize(),
                        async: true,
                        beforeSend: function (xhr, settings) {
                            xhr.setRequestHeader("X-CSRFToken", "{{ csrf_token }}");
                        },
                        success: function (data) {
                            window.alert(data.message);
                        }
                    });
             });
                $('#createmore').on('click', function () {
                    $.ajax({
                        cache: false,
                        type: "POST",
                        url: "{% url 'topnews:tokencreatmore' %}",
                        data: $('#createmoredata').serialize(),
                        async: true,
                        beforeSend: function (xhr, settings) {
                            xhr.setRequestHeader("X-CSRFToken", "{{ csrf_token }}");
                        },
                        success: function (data) {
                            if (data.status=="success"){
                                {#diag.Title = data.num+"个"+data.title+"注册码创建成功!";#}
                                var str='<tr><th>NO.</th><th>注册码</th></tr>'
                                var index=1;
                                var list=data.list;
                                for(var i in list) {
                                    str = str + '<tr><th>'+index+'</th><th>'+list[i]+'</th></tr>'
                                    index += 1;
                                }
                                {#$('#tokendisplay').html(str);#}
                                $('#modal-container-873864').modal('show');
                                $('#modal-container-873864').find('#tokendisplay').html(str)
                            }else{
                                 window.alert(data.message);
                                }
                            }
                     });
                });
                $('#createindex').on('click', function () {
                    $.ajax({
                        cache: false,
                        type: "POST",
                        url: "{% url 'topnews:tokencreateindex' %}",
                        data: $('#createindexdata').serialize(),
                        async: true,
                        beforeSend: function (xhr, settings) {
                            xhr.setRequestHeader("X-CSRFToken", "{{ csrf_token }}");
                        },
                        success: function (data) {

                            if (data.status=="success"){
                                {#diag.Title = data.num+"个"+data.title+"注册码创建成功!";#}
                                var str='<tr><th>NO.</th><th>注册码</th></tr>'
                                var index=1;
                                var list=data.list;
                                for(var i in list) {
                                    str = str + '<tr><th>'+index+'</th><th>'+list[i]+'</th></tr>'
                                    index += 1;
                                }
                                {#$('#tokendisplay').html(str);#}
                                $('#modal-container-873864').modal('show');
                                $('#modal-container-873864').find('#tokendisplay').html(str)
                            }else{
                                 window.alert(data.message);
                                }
                        }
                    });
             });
                $('#transfer').on('click', function () {
                    $.ajax({
                        cache: false,
                        type: "POST",
                        url: "{% url 'topnews:transfer' %}",
                        data: $('#transferdata').serialize(),
                        async: true,
                        beforeSend: function (xhr, settings) {
                            xhr.setRequestHeader("X-CSRFToken", "{{ csrf_token }}");
                        },
                        success: function (data) {
                            window.alert(data.message);
                        }
                    });
             });

        </script>

{% endblock base_footer_html %}
